(function(a) {
a.fn.jContent = function(b) {
var f = "div.slides"
, e = "next"
, c = false
, d = "horizontal"
, g = this
, b = a.extend({
speed: 500,
orientation: d,
auto: c,
direction: e,
pause: 5e3,
circle: c,
easing: "",
xml: "",
pause_on_hover: c,
width: 655,
height: 170,
videos: c
}, b);
this.init = function(g) {
var h = "prev"
, m = "vertical"
, l = "div.panel"
, k = "left"
, j = "height"
, i = "width"
, n = "position";
g.div = a(g);
g.slides_div = a(g).children(f).css("overflow", "hidden").css(n, "relative").css(i, b.width).css(j, b.height).css("float", k);
g.currentSlide = 0;
g.lastDirection = "";
g.isMouseHover = c;
g.intervalId;
g.div.addClass("jContent");
if (b.orientation == d)
g.div.addClass("jc-horizontal");
else
g.div.addClass("jc-vertical");
b.auto && g.div.addClass("jc-auto");
b.circle && g.div.addClass("jc-circle");
g.slides = g.slides_div.children("div").css(i, b.width).css(j, b.height).hide();
g.count = g.slides.length;
g.left_arr = g.div.children("a").eq(0);
g.right_arr = g.div.children("a").eq(1);
g.slides_div.append("
");
g.panel = g.slides_div.children(l).css(n, "absolute");
switch (b.orientation) {
case d:
g.slides.css("float", k);
g.panel.css(i, 3 * b.width).css(j, b.height);
break;
case m:
g.panel.css(j, 3 * b.height).css(i, b.width)
}
g.getNextIndex = function() {
return g.currentSlide >= g.count - 1 ? -1 : g.currentSlide + 1
}
;
g.getPrevIndex = function() {
return g.currentSlide <= 0 ? g.count - 1 : g.currentSlide - 1
}
;
g.clone_slide = function(b) {
var a = g.slides.eq(b).show()
, c = "" + a.html() + "
";
a.hide();
return c
}
;
g.initItemsPosition = function(a) {
if (g.panel.children().length == 0) {
g.panel.append(g.clone_slide(g.getPrevIndex()));
g.panel.append(g.clone_slide(g.currentSlide));
g.panel.append(g.clone_slide(g.getNextIndex()))
} else if (a == h) {
g.panel.prepend(g.clone_slide(g.getPrevIndex()));
g.panel.children().eq(3).remove();
b.videos && g.panel.children().eq(2).replaceWith(g.slides.eq(g.getNextIndex()).show())
} else {
g.panel.append(g.clone_slide(g.getNextIndex()));
g.panel.children().eq(0).remove();
b.videos && g.panel.children().eq(0).replaceWith(g.slides.eq(g.getPrevIndex()).show())
}
switch (b.orientation) {
case d:
g.panel = g.slides_div.children(l).css(k, -1 * b.width);
break;
case m:
g.panel = g.slides_div.children(l).css("top", -1 * b.height)
}
}
;
g.isLastItem = function() {
return g.currentSlide >= g.count - 1
}
;
g.isFirstItem = function() {
return g.currentSlide <= 0
}
;
g.updateArrows = function() {
var c = "show"
, a = "hide";
if (g.count > 1) {
if (!b.auto && !b.circle)
if (g.isLastItem()) {
g.left_arr.removeClass(a).removeClass(c).addClass(c);
g.right_arr.removeClass(a).removeClass(c).addClass(a)
} else if (g.isFirstItem()) {
g.left_arr.removeClass(a).removeClass(c).addClass(a);
g.right_arr.removeClass(a).removeClass(c).addClass(c)
} else {
g.left_arr.removeClass(a).removeClass(c).addClass(c);
g.right_arr.removeClass(a).removeClass(c).addClass(c)
}
} else {
g.left_arr.addClass(a);
g.right_arr.addClass(a)
}
}
;
g.getAnimateArgs = function(c) {
var a;
switch (b.orientation) {
case d:
if (c == h)
a = {
left: 0
};
else
a = {
left: -2 * b.width
};
break;
case m:
if (c == h)
a = {
top: 0
};
else
a = {
top: -2 * b.height
}
}
return a
}
;
g.performAimate = function(a) {
g.panel.animate(g.getAnimateArgs(a), b.speed, b.easing, function() {
if (a == h)
g.currentSlide = g.getPrevIndex();
else {
g.currentSlide = g.getNextIndex();}
g.initItemsPosition(a);
g.updateArrows();
b.auto == true && g.go(a)
})
}
;
g.animation = function(a) {
g.lastDirection = a;
if (b.auto)
setTimeout(function() {
if (b.pause_on_hover && g.isMouseHover)
g.intervalId = setInterval(function() {
if (!g.isMouseHover) {
clearInterval(g.intervalId);
g.performAimate(a)
}
}, 250);
else if(!g.isLastItem()) //added if condition to stop animation by ni
g.performAimate(a)
}, b.pause);
else
g.performAimate(a)
}
;
g.go = function(a) {
if (a == h)
(!g.isFirstItem() || b.auto || b.circle) && g.animation(h);
else
(!g.isLastItem() || b.auto || b.circle) && g.animation(e)
}
;
g.left_arr.click(function() {
g.go(h);
return c
});
g.right_arr.click(function() {
g.go(e);
return c
});
g.div.mouseenter(function() {
if (b.pause_on_hover)
g.isMouseHover = true
});
g.div.mouseleave(function() {
if (b.pause_on_hover)
g.isMouseHover = c
});
g.updateArrows();
g.initItemsPosition("");
b.auto && g.go(b.direction)
}
;
return this.each(function() {
var d = this;
if (b.xml != "")
a.ajax({
url: b.xml,
type: "GET",
cache: c,
success: function(c) {
var b = a("slide", c);
a(d).html("");
b.each(function() {
a(d).find(f).append(a(this).text())
});
g.init(d)
},
dataType: "xml"
});
else
g.init(d)
})
}
}
)(jQuery);